#ifndef _FFTDLG_H
#define _FFTDLG_H

#include  "config.h"

class CFFTDlg : public CDialogImpl<CFFTDlg>, 
                 public CWinDataExchange<CFFTDlg>
{
	
public:
    enum { IDD = IDD_FFT };
 
    BEGIN_MSG_MAP(CFFTDlg)
        MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
        MESSAGE_HANDLER(WM_CLOSE, OnClose)
		COMMAND_ID_HANDLER(IDOK, OnOK)
        COMMAND_ID_HANDLER(IDCANCEL, OnCancel)

		//REFLECT_NOTIFICATIONS ()
	END_MSG_MAP()
 
    LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
    {
        CenterWindow();
		//Config::g_configFile.read();
		int rp=Config::FFT_ANAPoint;

        if(rp==128)
            aPoint=0;
		if(rp==256)
			aPoint=1;
		if(rp==512)
			aPoint=2;
		if(rp==1024)
			aPoint=3;
        //Convert real points into radio index

		aWin=Config::FFT_ANAWindow;
		interval = Config::FFT_Interval;
		isSequential = interval==0?false:true;

		DoDataExchange(FALSE);
        return TRUE;    // let the system set the focus

    }


    LRESULT OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
    {
        EndDialog(IDCANCEL);
        return 0;
    }

	LRESULT OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
    {
        EndDialog(wID);
        return 0;
    }
	LRESULT OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
    {
		if(DoDataExchange(TRUE)==0)
		{
			MessageBox(_T("Invalid value of width or height."));
			return 0;
		}

        int rp;

		if(aPoint==0)
			rp=128;
		if(aPoint==1)
			rp=256;
		if(aPoint==2)
			rp=512;
		if(aPoint==3)
			rp=1024;
        //Convert radio index into real points

		Config::FFT_ANAPoint = rp;
		Config::FFT_ANAWindow = aWin;
		Config::FFT_Interval = isSequential==false?0:interval;
		//Config::g_configFile.write();
        EndDialog(wID);
        return 0;
    }

	BEGIN_DDX_MAP(CFFTDlg)
		DDX_RADIO(IDC_RADIO1,aPoint)
		DDX_RADIO(IDC_RADIO13,aWin)
		DDX_UINT(IDC_EDIT1,interval)
		DDX_CHECK(IDC_CHECK1,isSequential)
    END_DDX_MAP()

protected:
	int aPoint, aWin;
	bool isSequential;
	unsigned int interval;
public:

};
#endif